<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper" style="height: 900px;">
    <div class="content" style="height: 900px;">
        <div class="location">商户管理</div>
        <{include file= "Restaurant/nav.html"}>

        <a class="return" href="<{u('storeList')}>">&lt;  返回</a>
        <div class="topic">添加门店信息</div>
        <div class="form-box border0 border-box">
            <form action="<{u('storeEdit')}>" class="ui-form" method="post" id="addManagerForm">
                <input type="hidden" name="id" value="<{$obj.id}>"/>
                <div class="ui-form-item">
                    <label class="ui-label">所属商家：</label>
                    <select name="restaurantId" id="restaurant" class="ui-select" style="width:200px;">
                        <{foreach from=$restaurant item=one}>
                            <option value="<{$one['id']}>" <{if $one['id'] eq $obj.restaurantId}>selected <{/if}>><{$one['restaurantName']}></option>>
                        <{/foreach}>
                    </select>
                </div>
                <div class="ui-form-item">
                    <label class="ui-label">门店名称：</label>
                    <input type="text" class="ui-text" name="storeName" value="<{$obj.storeName}>" required/>
                </div>
                <div class="ui-form-item inline-block" style="position: relative;">
                    <input type="hidden" name="province" value="<{$obj.province}>" id="province" />
                    <input type="hidden" value="<{$obj.provinceName}>" id="provinceName" />
                    <input type="hidden" name="city" value="<{$obj.city}>" id="city" />
                    <input type="hidden" value="<{$obj.cityName}>" id="cityName" />
                    <input type="hidden" name="district" value="<{$obj.district}>" id="district" />
                    <input type="hidden" value="<{$obj.districtName}>" id="districtName" />
                    <input type="hidden" value="<{$obj.province}>/<{$obj.city}>/<{$obj.district}>" id="selectAddress" />
                    <label class="ui-label">详细地址</label>
                    <input class="ui-select" readonly type="text" id="showSelectAdd" value="<{$address}>" placeholder="省/市/区" style="padding-left:10px; width:220px;" onclick="TestBlack('carnub1');">
                    <div class="DistrictsBox carnubbox" id="carnub1" style="display:none; position:absolute; z-index:999">
                        <ul class="tab_topic">
                            <li style="width: 106px;" id="tab_to_1" class="no"><a onclick="tab('tab',3,1)">省份</a></li>
                            <li style="width: 106px;" id="tab_to_2" onclick="tab('tab',3,2)"><a>城市</a></li>
                            <li style="width: 106px;" id="tab_to_3" onclick="tab('tab',3,3)"><a>区县</a></li>
                        </ul>
                        <div class="tab_con">
                            <div id="tab_mo_1" class="Province" style="padding-top: 1px;">
                                <{foreach from=$province item=group key=key}>
                                <div class="ProvinceBox">
                                    <span><{$key}></span>
                                    <ul>
                                        <{if $group}>
                                        <{foreach from=$group item=item key=key}>
                                        <li id="<{$key}>" onclick='area_tab("tab",3,2,"<{$key}>","<{$item.short_name}>")'><{$item.short_name}></li>
                                        <{/foreach}>
                                        <{/if}>
                                    </ul>
                                </div>
                                <{/foreach}>
                            </div>
                            <div id="tab_mo_2" class="city" style="display:none;">
                            </div>
                            <div id="tab_mo_3" class="district" style="display:none;">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="ui-form-item ">
                    <label class="ui-label ">&nbsp;</label>
                    <input type="text" class="ui-text" name="address" placeholder="xx街道xxx小区XX座XX号XXXX室" title="<{$obj.address}>" value="<{$obj.address}>" required/>
                </div>
                <div class="ui-form-item ">
                    <label class="ui-label">手机号：</label>
                    <input type="text" class="ui-text" name="phone" value="<{$obj.phone}>" />
                </div>

                <div class="ui-form-item">
                    <label class="ui-label">联系人：</label>
                    <input type="text" class="ui-text" name="director" value="<{$obj.director}>" />
                </div>
                <div class="integral_btn-group">
                    <input type="submit" value="提交" class="ui-button"/>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<{include file="Public/foot.html" }>
<script>
    function TestBlack(TagName){
        var obj = document.getElementById(TagName);
        if(obj.style.display==""){
            obj.style.display = "none";
        }else{
            obj.style.display = "";

            var address = $("#selectAddress").val();
            addr = address.split("/");
            var length = addr.length;
            var askLevel = length+1;
            var i;
            for(i=0;i<length;i++){
                if(addr[i] <= 0){
                    askLevel = parseInt(i+1);
                    break;
                }
            }
            if(askLevel > 3) askLevel = 3;
            tab('tab',3,askLevel);
        }
    }

    function tab(a,b,c) {
        for(i=1;i<=b;i++){
            if(c==i)
            {
                // 判断选择模块
                document.getElementById(a+"_mo_"+i).style.display = "block";  // 显示模块内容
                document.getElementById(a+"_to_"+i).className = "no";   // 改变菜单为选中样式

                var address = $("#selectAddress").val();
                addr = address.split("/");
                length = addr.length;
                var arrLength = 0;
                for(z=0;z<length;z++){
                    if(addr[z] > 0){
                        arrLength++;
                    }
                }
                if(c > arrLength+1){
                    //清空后两级数据(例如，只选择了省级数据，区和街道数据应清空)
                    for(var j=arrLength+2;j<=b;j++){
                        $("#"+a+"_mo_"+j).empty();
                    }
                } else {
                    if(c==1){
                        //显示省级数据
                        $("#"+addr[0]).attr('class','active');
                    } else{
                        area_id = addr[c-2];
                        var param = {provinceID:addr[0],area_id:area_id,level:c};

                        $.post("<{U('Restaurant/getArea_info')}>",param,function (res) {
                            if(res.status == 1){
//                                        layer.msg(res.msg);
                            }else{
                                $("#"+a+"_mo_"+c).empty().append(res.dataHtml);
                                $("#"+addr[c-1]).attr('class','active');
                            }
                        });
                    }

                }
            }
            else{
                // 没有选择的模块
                document.getElementById(a+"_mo_"+i).style.display = "none"; // 隐藏没有选择的模块
                document.getElementById(a+"_to_"+i).className = "";  // 清空没有选择的菜单样式
            }
        }
    }

    function area_tab(a,b,c,id,name) {
        tab(a,b,c);
        orginalLevel = c-1;     //点击的那一级
        $("#"+a+"_mo_"+orginalLevel+" ul").find("li").each(function () {
            if ($(this).hasClass('active')) {
                $(this).removeClass('active');
            }
        });
        switch (parseInt(c)){
            case 2:
                $("#province").val(id);
                $("#provinceName").val(name);
                $("#showSelectAdd").val(name);
                $("#selectAddress").val(id);
                $("#city,#district").val('');
                $("#cityName,#districtName").val('');
                break;
            case 3:
                $("#city").val(id);
                $("#cityName").val(name);
                $("#showSelectAdd").val($("#provinceName").val()+'/'+name);
                $("#selectAddress").val($("#province").val()+'/'+id);
                $("#district").val('');
                $("#districtName").val('');
                break;
            case 4:
                $("#district").val(id);
                $("#districtName").val(name);
                $("#showSelectAdd").val($("#provinceName").val()+'/'+$("#cityName").val()+'/'+name);
                $("#selectAddress").val($("#province").val()+'/'+$("#city").val()+'/'+id);
                break;
        }
        $("#"+id).attr('class','active');
        if(c < 4){
            $("#"+a+"_mo_"+c+"").empty();
            var provinceID = $("#province").val();
            var param = {provinceID:provinceID,area_id:id,level:c};
            $.post("<{U('Restaurant/getArea_info')}>",param,function (res) {
                if(res.status == 1){
                    layer.msg(res.msg);
                }else{
                    $("#"+a+"_mo_"+c+"").empty().append(res.dataHtml);
                }
            });
        } else if(c == 4){
            //关闭地址选择器
            TestBlack('carnub1');
        }

    }
</script>